//
//  JBWDelegateView.m
//  JBWDSK
//
//  Created by 崔志伟 on 2018/7/27.
//  Copyright © 2018年 崔志伟. All rights reserved.
//

#import "JBWDelegateView.h"

@interface JBWDelegateView ()<UITextViewDelegate>
@property (nonatomic,strong) UITextView  * delegateTextView ;

@end

@implementation JBWDelegateView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self  = [super initWithFrame:frame]) {
        
        self.delegateTextView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, 220, self.bounds.size.height)];
        self.delegateTextView.center = CGPointMake(self.bounds.size.width/2.0, self.bounds.size.height/2.0);
        self.delegateTextView.backgroundColor = [UIColor clearColor];
        self.delegateTextView.delegate = self;
        self.delegateTextView.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.delegateTextView];
        [self setUpDelegateTextView];
    
    }
    return self;
}


- (void)setUpDelegateTextView {
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 5;// 字体的行间距
    NSDictionary *attributes = @{NSParagraphStyleAttributeName:paragraphStyle};
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"注册即代表您同意使用条款与隐私政策"];
    [attributedString addAttributes:attributes range:NSMakeRange(0, attributedString.length)];
    [attributedString addAttribute:NSLinkAttributeName  value:@"jbwRegisterAgreement://" range:[[attributedString string] rangeOfString:@"使用条款与隐私政策"]];
    self.delegateTextView.attributedText = attributedString;
    self.delegateTextView.linkTextAttributes = @{NSForegroundColorAttributeName: [UIColor orangeColor],NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)};
    self.delegateTextView.textColor = JBW_HEX_COLOR(0xA6A6AC );
    self.delegateTextView.editable = NO;//必须禁止输入，否则点击将弹出输入键盘
    self.delegateTextView.scrollEnabled = NO;
}
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
    if ([[URL scheme] isEqualToString:@"jbwRegisterAgreement"]) {
        
        return NO;
    }
    return YES;
}
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    return NO;
}
@end
